package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.hotel.domain.stations.DicCityBrandVo;
import com.ktgj.hotel.domain.stations.DicHotPositionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.hotel.domain.DicHotPosition;
import com.ktgj.hotel.service.IDicHotPositionService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-12-09
 */
@ControllerAdvice
@RestController
@RequestMapping("/hotPosition")
public class DicHotPositionController extends BaseController
{
    @Autowired
    private IDicHotPositionService dicHotPositionService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:position:list")
    @GetMapping("/list")
    public TableDataInfo list(DicHotPosition dicHotPosition)
    {
        startPage();
        List<DicHotPosition> list = dicHotPositionService.selectDicHotPositionList(dicHotPosition);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "hotel:position:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DicHotPosition dicHotPosition) throws IOException
    {
        List<DicHotPosition> list = dicHotPositionService.selectDicHotPositionList(dicHotPosition);
        ExcelUtil<DicHotPosition> util = new ExcelUtil<DicHotPosition>(DicHotPosition.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "hotel:position:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(dicHotPositionService.selectDicHotPositionById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:position:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DicHotPosition dicHotPosition)
    {
        return toAjax(dicHotPositionService.insertDicHotPosition(dicHotPosition));
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:position:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DicHotPosition dicHotPosition)
    {
        return toAjax(dicHotPositionService.updateDicHotPosition(dicHotPosition));
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "hotel:position:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dicHotPositionService.deleteDicHotPositionByIds(ids));
    }

    @PostMapping("/queryCityIdByHotPosition")
    public AjaxResult queryCityIdByHotPosition(@RequestBody Map<String, Object> map) {
        Long cityId = (Long) map.get("cityId");
        List<DicHotPositionVo> dicHotPositionVos = dicHotPositionService.queryCityIdByHotPosition(cityId);
        if (dicHotPositionVos != null) {
            return AjaxResult.success(dicHotPositionVos);
        } else {
            return AjaxResult.error("站点查询失败");
        }
    }

    /**
     * 酒店查询条件（热门区域）
     * */
    @PostMapping("/popularAreaList")
    public AjaxResult popularAreaList(@RequestBody Map<String, Object> map){
        Long cityId;
        try {
            cityId = Long.valueOf(map.get("cityId").toString());
        } catch (Exception e){
            return AjaxResult.error("未传入参数");
        }

        List<DicHotPosition> hotPositionList = dicHotPositionService.popularAreaList(cityId);
        if (hotPositionList != null && hotPositionList.size() > 0){
            return AjaxResult.success(hotPositionList);
        }
        else {
            return AjaxResult.error("未查询到数据");
        }
    }
}
